package com.zhou.springboot.service.impl;

import com.zhou.springboot.dao.PersonDao;
import com.zhou.springboot.entity.Person;
import com.zhou.springboot.service.PersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

/**
 * author : zhoujb
 * created : 2020/7/12.
 * QQ : 1377072049
 */
@Service
public class PersonServiceImpl implements PersonService {
    @Autowired
    private PersonDao personDao;
    @Override
    @Transactional
    public void insertPerson(Person person) throws Exception{
        personDao.save(person);
    }
    @Transactional
    @Override
    public void deletePerson(Long id) {
        personDao.deleteById(id);
    }

    @Override
    @Transactional
    public void updatePerson(Person person) {
        System.out.println(person);
        personDao.updatePerson(person);
    }

    @Override
    public List<Person> findAllPerson() {
        return personDao.findAll();
    }

    @Override
    public Person findPersonById(Long id) {
        Optional<Person> optionalPerson = personDao.findById(id);
        return  optionalPerson.get();
    }
}
